package cn.tkb.basic.service.impl;

import cn.tkb.basic.mapper.BaseMapper;
import cn.tkb.basic.service.IBaseService;
import cn.tkb.basic.util.PageQuery;
import cn.tkb.basic.query.BaseQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly =true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;
    @Override
    @Transactional
    public void add(T t) {
        mapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        mapper.delete(id);
    }

    @Override
    public T QeuryById(Long id) {
        return mapper.loadById(id);
    }

    @Override
    public List<T> QeuryAll() {
        return mapper.loadAll();
    }

    @Override
    public PageQuery<T> findPage(BaseQuery query) {
        Long total = mapper.loadCount(query);
        List<T> data = mapper.pageList(query);
        return new PageQuery<>(total,data);
    }

    @Override
    @Transactional
    public void BatchDelete(List<Long> ids) {
        mapper.BatchDelete(ids);
    }
}
